# 对称二叉树

import pickle


# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def isSymmetric(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        # 如果没有结点
        if not root:
            return True
        return self.isSame(root.left, root.right)

    def isSame(self, left, right):
        if not (left or right):
            return True
        if not (left and right):
            return False
        if not left.val == right.val:
            return False
        return self.isSame(left.left, right.right) and self.isSame(left.right, right.left)
